package ch.fhnw.qualiscan.application.modals;

import java.util.List;

import ch.fhnw.qualiscan.Config;
import ch.fhnw.qualiscan.application.models.AdminModel;
import ch.fhnw.qualiscan.application.pages.tabs.AdminTab1;
import ch.fhnw.qualiscan.core.Modal;
import ch.fhnw.qualiscan.core.db.helpers.adminDomainTableArgs;
import ch.fhnw.qualiscan.core.db.pojos.Language;

import com.vaadin.ui.Button;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Button.ClickEvent;

import eu.livotov.tpt.i18n.TM;

@SuppressWarnings("serial")
public class AdminDeleteDomain extends Modal {
	
	private adminDomainTableArgs adta;
	private Form editForm;
	private AdminModel adminModel;
	private List<Language> langList;
	private AdminTab1 caller;
	
	public AdminDeleteDomain(adminDomainTableArgs adta, AdminTab1 caller) {
		setCaption(TM.get("admin.deletedomain.title"));
		this.adta = adta;
		this.caller = caller;
		
		adminModel = new AdminModel();
		langList = adminModel.getLanguages();
		buildLayout();
	}
	
	public void buildLayout() {
		addComponent(textHelper.p(TM.get("admin.deletedomain.desc")));
		HorizontalLayout buttonBar = new HorizontalLayout();
		buttonBar.setSpacing(true);
		buttonBar.setMargin(true, false, false, false);
		addComponent(buttonBar);
		
		Button confirmButton = new Button(TM.get("action.confirm"), new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				adminModel.deleteDomain(adta.getDomain());
				caller.tableContainer.removeItem(adta);
				caller.admin.tabComponent2.refresh();
				AdminDeleteDomain add = (AdminDeleteDomain) event.getButton().getData();
				add.close();
			}
		});
		confirmButton.setIcon(Config.ICON_ACCEPT);
		confirmButton.setData(this);
		
		Button cancelButton = new Button(TM.get("action.cancel"), new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				AdminDeleteDomain add = (AdminDeleteDomain) event.getButton().getData();
				add.close();
			}
		});
		cancelButton.setIcon(Config.ICON_CANCEL);
		cancelButton.setData(this);
	
		buttonBar.addComponent(confirmButton);
		buttonBar.addComponent(cancelButton);
	}
	
}
